﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace Universum.Model.Services
{
	/// <summary>
	/// Helper class for getting special values from the current request
	/// </summary>
	public static class WebSiteContextHelperService
	{
		public static string WebSiteBaseUrl
		{
			get
			{
				return HttpContext.Current.Request.Url.GetComponents(UriComponents.SchemeAndServer, UriFormat.Unescaped);
			}
		}

		public static string WebSiteWithUser
		{
			get
			{
				var result = HttpContext.Current.Request.Url.GetComponents(UriComponents.SchemeAndServer, UriFormat.Unescaped);
				var appPath = HttpContext.Current.Request.ApplicationPath;
				string username = "anonymous";
				if(HttpContext.Current.User != null &&
					HttpContext.Current.User.Identity != null) username = HttpContext.Current.User.Identity.Name;

				result += (appPath.Equals("/") ? "" : appPath) + "/" +
					username;

				return result;
			}
		}
	}
}
